package com.bwie.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.pojo.TbStudent;
import com.bwie.service.IClazzServer;
import com.bwie.service.TbStudentService;
import com.bwie.mapper.TbStudentMapper;
import com.bwie.utils.R;
import com.bwie.vo.ClazzVO;

import com.bwie.vo.StudentPageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lenovo
 * @description 针对表【tb_student(学生表)】的数据库操作Service实现
 * @createDate 2025-06-21 10:55:14
 */
@Service
public class TbStudentServiceImpl extends ServiceImpl<TbStudentMapper, TbStudent>
        implements TbStudentService {

    @Autowired
    TbStudentMapper tbStudentMapper;

    @Autowired
    IClazzServer iClazzServer;

    @Override
    public R getStudentList(StudentPageVo studentPageVo) {
        //分页参数
        Page<TbStudent> page = new Page<>(studentPageVo.getPageNum(), studentPageVo.getPageSize());
        //分页查询列表
        Page<TbStudent> tbStudentPage = tbStudentMapper.getStudentList(page, studentPageVo);

        tbStudentPage.getRecords().forEach(item -> {
            //  数据脱敏：页面数据展示要求：隐藏学生手机号中间6位数字，例如“185*******12”（2分）
            item.setPhone(item.getPhone().substring(0, 3) + "******"+item.getPhone().substring(9));
            //  数据脱敏：页面数据展示要求：隐藏身份证 前4后4展示，中间全部以“*”号代替（2分）
            item.setIdCard(item.getIdCard().substring(0,4)+"**********"+item.getIdCard().substring(14));
        });

        //返回值
        return R.OK(tbStudentPage);
    }

    @Override
    public R getClazzList() {

        R clazz = iClazzServer.getClazz();

        String s = JSON.toJSONString(clazz.getData());

        List<ClazzVO> voList = JSON.parseArray(s, ClazzVO.class);

        return R.OK(voList);
    }
}




